﻿using Ndns.ServerHost.Abstractions;
using Ndns.ServerHost.Abstractions.Services;
using System;

namespace Ndns.Cache
{
    class DnsCacheEntry
    {
        public DnsQueryKey Key { get; }
        public DnsQueryAnswers Value { get; }
        public DateTime CreationDateTime { get; }

        public DateTime LastAccessDateTime { get; set; }
        public DateTimeOffset AbsoluteExpiration { get; set; }

        public CachePriority Priority { get; }

        public DnsCacheEntry(DnsQueryKey key, DnsQueryAnswers value, TimeSpan timeToLive, CachePriority priority)
        {
            Key = key;
            Value = value;
            LastAccessDateTime = DateTime.UtcNow;
            AbsoluteExpiration = LastAccessDateTime + timeToLive;
            Priority = priority;
        }

        public bool CheckExpired(DateTimeOffset now)
        {
            return AbsoluteExpiration <= now;
        }
    }
}
